package com.csun.cmny.provider.controller.admin;

import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.domain.DmcYingShiConfig;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.DmcYingShiConfigService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2021/8/27 16:38
 * @Description: 萤石应用信息控制器
 */
@RestController
@RequestMapping(value = "/yingShiConfig", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class DmcYingShiConfigController extends BaseController {

    @Resource
    private CmnyMessageSource cmnyMessageSource;
    @Resource
    private DmcYingShiConfigService dmcYingShiConfigService;

    /**
     * 查询萤石应用信息
     */
    @RequestMapping(value = "/select", method = RequestMethod.POST)
    public Wrapper select() {

        DmcYingShiConfig dmcYingShiConfig = dmcYingShiConfigService
                .selectByKey(getLoginAuthDto().getGroupId());

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,
                cmnyMessageSource.getMessage("operation.success", null),
                dmcYingShiConfig);
    }

    /**
     * 保存萤石应用信息
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Wrapper save(@RequestBody DmcYingShiConfig dmcYingShiConfig) {

        Integer result = dmcYingShiConfigService.save(dmcYingShiConfig, getLoginAuthDto());
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE,
                    cmnyMessageSource.getMessage("operation.failed",null));
        }

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,
                cmnyMessageSource.getMessage("operation.success", null),
                dmcYingShiConfig);
    }
}
